package ch.eureka.consumer.ribbon.controller;

import ch.eureka.consumer.ribbon.service.ProviderWithHystrix;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProviderWithHystrix hystrix;

    @RequestMapping(value = "/ribbon-consumer",method = RequestMethod.GET)
    public String helloConsumer(){
        /**
         *  getForEntity("地址?name={1}",返回数据的格式,"数据")
         */
        return restTemplate.getForEntity("http://eureka-provider/hello",String.class).getBody();
    }

    /**
     * 断路器的使用
     * @return
     */
    @RequestMapping(value = "/ribbon-consumer-hystrix", method = RequestMethod.GET)
    public String hystrix(){
        return hystrix.hello(1L);
    }
}
